<template>
  <div class="app-container">
    <div class="search">
      <p class="float-left mr-10 mb-10" style="width: 200px">
        <el-input v-model="searchParams.name" placeholder="输入名称"></el-input>
      </p>
      <p class="float-left mr-10 mb-10">
        <el-button type="primary" @click="searchSpace">搜索</el-button>
        <el-button type="primary" @click="resetSpace">重置</el-button>
      </p>
    </div>
    <bdTable :tableHeader="tableHeader" :tableData="tableData" class="mb-10" />
    <bd-page
      :pageSize="pages"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    ></bd-page>
    <spaceAudit ref="spaceInfo" @update:visible="searchSpace"/>
  </div>
</template>
<script>
import { pyqPage, deletePyq } from '@/api/pyq'
import spaceAudit from './spaceAudit.vue'
export default {
  name: '',
  components: {
    spaceAudit
  },
  data () {
    return {
      searchParams: {
        name: null
      },
      tableHeader: {
        type: 'selection',
        header: [
          {
            prop: 'detail',
            label: '内容',
            minWidth: 180
          },
          {
            prop: 'status',
            type: 'tag',
            label: '审核状态',
            statusType: (row) => {
              return row.status ? (row.status === 1 ? 'success' : 'danger') : 'warning'
            },
            filter: (row) => {
              return row.status ? (row.status === 1 ? '已通过' : '已驳回') : '待审核'
            }
          },
          {
            prop: 'createTime',
            label: '创建日期',
            minWidth: 150
          },
          {
            label: '操作',
            type: 'button',
            minWidth: 150,
            btn: [
              {
                id: 1,
                name: '审核',
                handler: this.handleAudit,
                disabled: (row) => {
                  return row.status !== 0
                }
              },
              {
                id: 2,
                name: '删除',
                type: 'danger',
                handler: this.handleDelete
              }
            ]
          }
        ]
      },
      // 列表数据
      tableData: [],
      // 分页
      pages: {
        page: 1,
        pageSize: 10
      },
      total: 0
    }
  },
  // 计算属性
  computed: {},
  watch: {},
  mounted () {
    this.searchSpace()
  },
  methods: {
    async searchSpace (clearPage = false) {
      if (clearPage) {
        this.pages.page = 1
        this.pages.pageSize = 10
      }
      const params = {
        ...this.pages,
        ...this.searchParams
      }
      const { total, list } = await pyqPage(params)
      this.total = total
      this.tableData = list
    },
    // 重置
    resetSpace () {
      this.searchParams.name = ''
      this.searchSpace(true)
    },
    // 审核
    handleAudit (e, row) {
      this.$refs.spaceInfo.isShow(row)
    },
    // 删除
    handleDelete (e, row) {
      this.$confirm('此操作将永久删除, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        await deletePyq({ pyqId: row.pyqId })
        this.searchSpace()
      }).catch(() => {
      })
    },
    // 条数
    handleSizeChange (val) {
      this.pages.pageSize = val
      this.searchSpace()
    },
    // 页数
    handleCurrentChange (val) {
      this.pages.page = val
      this.searchSpace()
    }
  }
}
</script>
<style lang="scss" scoped>
</style>
